package cs342.project1.mathNotebook.gui;

import java.awt.Component;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;


import javax.swing.BoxLayout;
import javax.swing.ButtonGroup;
import javax.swing.DefaultCellEditor;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;

import cs342.project1.mathNotebook.db.*;
import cs342.project1.mathNotebook.gui.RadioButtonEditor;
import cs342.project1.mathNotebook.gui.RadioButtonPanel;
import cs342.project1.mathNotebook.gui.RadioButtonRenderer;


	public class CustomTableModel extends JFrame {

		public CustomTableModel() {
		    super("CustomTableModel");

		    DefaultTableModel dm = new DefaultTableModel(){

					@Override  
		    	     public boolean isCellEditable(int row, int column)  
		    	     {   
		    	         
		    	         if(column == 0){
		    	        	 return false; 
		    	         }
		    	         else return true;

		    	     }
		    	
		    };
                    DatabaseContext context = null;
                    DBPerson[] people = null;
                    String[][] names = null;
                    try{
                        context = new DatabaseContext("resources/prop.properties");
                        DBPerson.createPerson(context, "testUser", "Test User", "user@test.com", new byte[] { 'a', 'b' , 'c'}).invalidate();
                        people = DBPerson.getAllPersons(context);
                        names = new String[4][1];
                        for(int i = 0; i < 4; i++){
                            
                            names[i][0] = Integer.toString(i);
                        }
                        
                        }catch(cs342.project1.mathNotebook.db.DatabaseUnconnectableException e){}
                        catch(java.io.FileNotFoundException e2){}
                        catch(java.io.IOException e3){}
                        catch(cs342.project1.mathNotebook.db.DatabaseException e){}
            
                        names = new String[4][1];
                        for(int i = 0; i < 4; i++){
                            
                            names[i][0] = Integer.toString(i);
                        }
                        for(int i = 0; i<4; i++){
                            System.out.println(names[i][0]);
                        }
                            
                            
                            
                        
                    
                    
		    dm.setDataVector(names
		        ,
		        new Object[] { "Username", "Permissions" });
		    
		    
		    JTable table = new JTable(dm);
		    
		    
		    
		    String[] options = { "Read", "Read/Write", "None" };

		    table.getColumn("Permissions").setCellRenderer(
		        new RadioButtonRenderer(options));
		    table.getColumn("Permissions").setCellEditor(
		        new RadioButtonEditor(new JCheckBox(), new RadioButtonPanel(
		            options)));
		    JScrollPane scroll = new JScrollPane(table);
		    getContentPane().add(scroll);
		    
		  }
		
		

  
}
